﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
namespace DAO
{
    public class COMMENTDAO
    {
        public static void Add_comment(COMMENT cmm)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            db.COMMENTs.InsertOnSubmit(cmm);
            db.SubmitChanges();

        }
        public static COMMENT[] layBang()
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            var v = from q in db.COMMENTs
                    select q;
            return v.ToArray();
        }
        public static COMMENT[] layBangByID(int id)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            var v = from q in db.COMMENTs
                    where q.IDPRODUCT == id
                    select q;
            return v.ToArray();
        }
        //thêm mới function by TUY

        public static COMMENT layCommentByID(int id)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            return db.COMMENTs.Single(c => c.IDCOMMENT == id);
        }
        public static bool updateComment(COMMENT cm)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            COMMENT comment = db.COMMENTs.Single(c => c.IDCOMMENT == cm.IDCOMMENT);
            comment.CONTENT = cm.CONTENT;
            comment.TIME = cm.TIME;
            db.SubmitChanges();
            return true;
        }
        public static bool deleteCommentById(int id)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            COMMENT comment = db.COMMENTs.Single(c => c.IDCOMMENT == id);
            db.COMMENTs.DeleteOnSubmit(comment);
            db.SubmitChanges();
            return true;
        }
    }
}
